import React, { Component } from 'react';

class Clock extends Component {

  constructor() {
    super()
    this.state = {
      date: new Date()
    }
  }

  render() {
    return (
      <div>
        <h1>
          {this.state.date.toLocaleTimeString()}
        </h1>
      </div>
    );
  }

  componentDidMount() {
    this.timer = setInterval(() => {
      this.setState({
        date: new Date()
      })
    }, 1000);
  }

  componentWillUnmount() {
    clearInterval(this.timer);
  }
}

export default Clock;